package com.money.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.money.entity.Book;
import com.money.mapper.BookMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookService {
    @Resource
    private BookMapper bookMapper;

    public PageInfo<Book> bookList(Integer pageNo, Integer size, String author, String publish) {
        PageHelper.startPage(pageNo, size);
        List<Book> books = bookMapper.selectAll(author, publish);
        PageInfo<Book> bookInfo = new PageInfo<>(books,2);
        return bookInfo;
    }

    //添加图书
    public void addBooks(Book book) {
        bookMapper.insert(book);
    }

    //查询一个图书
    public Book selectOne(Integer bookId) {
        return this.bookMapper.selectByPrimaryKey(bookId);
    }

    //修改图书信息
    public void updateBook(Book book) {
        this.bookMapper.updateByPrimaryKey(book);
    }

    //删除图书信息
    public void deleteUser(Integer id) {
        this.bookMapper.deleteByPrimaryKey(id);
    }
}
